//
//  ZYTabbar.m
//  sinaWeiBo_yu
//
//  Created by 振宇陈 on 16/9/5.
//  Copyright © 2016年 振宇陈. All rights reserved.
//

#import "ZYTabbar.h"


@interface ZYTabbar()


@end
@implementation ZYTabbar


-(UIButton*) plusButton
{
    if (_plusButton ==nil) {
        UIButton* btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"compose_pic_add_highlighted"] forState:UIControlStateSelected];
        [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        _plusButton = btn;
        [btn sizeToFit];
        [self addSubview:_plusButton];
    }
    return _plusButton;
}
/**
 *  调整子控件的布局
 */
-(void) layoutSubviews
{
    [super layoutSubviews];
    CGFloat btnX = 0;
    CGFloat btnY = 0;
    CGFloat btnWidth = self.bounds.size.width/(self.items.count+1);
    CGFloat btnHeight = self.bounds.size.height;
    int i =0;
    for (UIView* tabbarButton in self.subviews) {
        if ([tabbarButton isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            if (i>=2) {
                btnX = (i+1)*btnWidth;
            }else
            {
                btnX = i*btnWidth;
            }
            tabbarButton.frame = CGRectMake(btnX, btnY, btnWidth, btnHeight );
            i++;
        }
    }
    self.plusButton.center = CGPointMake(self.bounds.size.width*0.5, self.bounds.size.height*0.5);
//    self.plusButton.bounds = CGRectMake(0, 0, self.plusButton.currentBackgroundImage.size.width, self.plusButton.currentBackgroundImage.size.height);
    NSLog(@"%@",self.subviews);
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
